﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataProcessing
{
    public class AnnotationData
    {
        public AnnotationData()
        {
            this.Dir = Direction.REVERSE;
            this.ChromeName = null;
            this.GeneName = null;
            this.Range = new ValueRange();
            this.XSonInfo = new List<ValueRange>();
        }

        public override string ToString()
        {
            return GeneName + "[" + Range.Start + "," + Range.End + "]";
        }
        public static bool Ready
        {
            get;set;
        }

        public static List<AnnotationData> Data
        {
            get;set;
        }

        public String GeneName
        {
            get;set;
        }

        public enum Direction
        {
            FORWARD,REVERSE
        };
        public Direction Dir
        {
            get;
            set;
        }

        public String ChromeName
        {
            get;set;
        }

        public ValueRange Range
        {
            get;
            set;
        }

        public List<ValueRange> XSonInfo
        {
            get;set;
        }

        public static List<AnnotationData> Search(ValueRange window,String chromeName)
        {
            var queryRet = from annotation in Data
                           where annotation.ChromeName == chromeName && annotation.Range.OverlappedLength(window) != 0
                           select annotation;
            return queryRet.ToList();
        }

        
            
         public static void Load(String fileName)
         {
             try
             {
                 AnnotationData.Ready = false;
                 AnnotationData.Data = AnnotationFileParser.GetFromFile(fileName);
                 AnnotationData.Ready = true;
             }
             catch (Exception ex)
             {
                 AnnotationData.Ready = false;
             }
             
         }
        
    }
}
